{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='../../plugin/redrain/template/web/common_nav'}
    {if $method == "chance_main"}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id="myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="web" />
                <input type="hidden" name="r" value="redrain.chance.main" id="r" />
                <input type="hidden" name="type" value="{$type}" />
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">机会来源</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $type_list $row}
                            <a href="{php echo createWebUrlPlugin('redrain.chance.main',array('themeid'=>$themeid,'type'=>$row['type']));}" class="btn {if $type == $row['type']}btn-primary{else}btn-default{/if}">
                                {$row['title']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                    {if count($themelist)>1 }
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">更新时间</label>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <!--                        {php echo view_form_field_daterange('createtime', array('start' => $start_day, 'end' => $end_day));}-->
                        {php echo view_form_field_daterange('createtime', array('start'=>date('Y-m-d H:i:s',$starttime),'end'=>date('Y-m-d H:i:s',$endtime)), true);}
                    </div>

                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-4 col-xs-4 col-md-4">
                        <input class="form-control" name="search_data" placeholder="输入报名手机号、微信昵称、客资姓名" type="text" value="{$_P['search_data']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
    {/if}

    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 100px">昵称</th>
                        <th style="width: 100px">姓名/电话</th>
                        <th style="width: 120px">机会类型</th>
                        <th style="width: 80px">机会操作</th>
                        <th style="width: 100px">操作后剩余机会</th>
                        <th style="width: 100px">时间</th>
                        <th style="width: 100px">操作管理员</th>
                        <th style="width: 80px;text-align: right">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $index $item}
                    <tr>
                        <td>{php echo $index+1;}</td>
                        <td>
                            <img src="{php echo tomedia($item['avatar']);}" width="28" style="width: 28px;height: 28px;padding: 1px;">
                            <br>
                            {$item['nickname']}
                        </td>
                        <td>{$item['username']}<br/>{$item['mobile']}</td>
                        <td>
                            {if $item['type']==-1}
                                {if $item['used_type']==1}
                                    <span class="label label-warning">机会使用：转发朋友圈</span>
<!--                                    <span class="label label-success">转发朋友圈</span>-->
                                {elseif $item['used_type']==3}
                                    <span class="label label-warning">机会使用：转发好友</span>
<!--                                    <span class="label label-success">转发好友</span>-->
                                {elseif $item['used_type']==2}
                                    <span class="label label-warning">机会使用：好友助力</span>
<!--                                    <span class="label label-primary">好友助力</span>-->
                                {elseif $item['used_type']==4}
                                    <span class="label label-warning">机会使用：商家赠送</span>
<!--                                    <span class="label label-info">商家赠送</span>-->
                                {elseif $item['used_type']==5}
                                    <span class="label label-warning">机会使用：后台管理员增加</span>
<!--                                    <span class="label label-default">后台管理员增加</span>-->
                                {else}
                                {/if}
                            {elseif $item['type']==1}
                            <span class="label label-success">转发朋友圈</span>
                            {elseif $item['type']==3}
                            <span class="label label-success">转发好友</span>
                            {elseif $item['type']==2}
                            <span class="label label-primary">好友助力-来自{$item['from_nickname']}</span>
                            {elseif $item['type']==4}
                            <span class="label label-info">商家赠送</span>
                            {elseif $item['type']==5}
                            <span class="label label-default">后台管理员增加</span>
                            {elseif $item['type']==9}
                            <span class="label label-default">好友下单-来自{$item['from_nickname']}</span>
                            {else}
                            {/if}
                        </td>
                        <td>
                            {if $item['chance']>0}
                            <span class="label label-success">+{$item['chance']}</span>
                            {else}
                            <span class="label label-warning">{$item['chance']}</span>
                            {/if}
                        </td>
                        <td>{$item['changed_chance']}</td>

                        <td>
                            {$item['created_at']}
                        </td>
                        <td>{if $item['admin_name']}管理员-{$item['admin_name']}{/if}</td>
                        <td style="text-align: right">
                            <a class="btn btn-primary btn-sm" style="width: 35px"  data-type="edit" href="{php echo createWebUrl('comm',array('themeid'=>$themeid,'op'=>'edit','id'=>$item['fan_id']));}"
                               title="给该用户增加机会" data-toggle="tooltip" data-placement="top"><i class="fa fa-heart"> </i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

{$pager}
<script type="text/javascript">
    $(document).ready(
        function (){

        }
    );
    function submitForm(){
        $("#r").val('redrain.chance.main');
        var form = document.getElementById("myform");
        form.submit();
    }
    function changeOrDelItem(e) {
        let uid = e.getAttribute("data-uid");
        let themeid = e.getAttribute("data-themeid");
        let cid = e.getAttribute("data-cid");
        let postUrl = e.getAttribute("data-edit-url");
        layer.msg('您确定给该用户删除机会吗？',{
            btn:['确定','取消'],
            yes:function (index) {
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data: {uid:uid,themeid:themeid,cid:cid},
                    success:function (e) {
                        let res = e.result;
                        let status = res.status;
                        let msg = res.msg;
                        if (status!=1){
                            layer.msg(msg);
                        }else{
                            layer.msg(msg);
                        }
                        parent.location.reload();
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                });
                // parent.location.reload();
            }
        });
    }
</script>
